from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-08-11 14:02:51.287166
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 11, Aug, 2022
Time: 14:02:59
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.1004
Nobs: 745.000 HQIC: -50.4429
Log likelihood: 9446.02 FPE: 9.99162e-23
AIC: -50.6577 Det(Omega_mle): 8.86176e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.294181 0.055421 5.308 0.000
L1.Burgenland 0.108353 0.036795 2.945 0.003
L1.Kärnten -0.106732 0.019501 -5.473 0.000
L1.Niederösterreich 0.207821 0.076724 2.709 0.007
L1.Oberösterreich 0.109172 0.074943 1.457 0.145
L1.Salzburg 0.254304 0.039298 6.471 0.000
L1.Steiermark 0.040974 0.051306 0.799 0.425
L1.Tirol 0.107565 0.041613 2.585 0.010
L1.Vorarlberg -0.061560 0.035699 -1.724 0.085
L1.Wien 0.050725 0.066276 0.765 0.444
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059846 0.115744 0.517 0.605
L1.Burgenland -0.032529 0.076846 -0.423 0.672
L1.Kärnten 0.046949 0.040727 1.153 0.249
L1.Niederösterreich -0.175371 0.160235 -1.094 0.274
L1.Oberösterreich 0.408423 0.156516 2.609 0.009
L1.Salzburg 0.287854 0.082072 3.507 0.000
L1.Steiermark 0.108272 0.107150 1.010 0.312
L1.Tirol 0.312028 0.086908 3.590 0.000
L1.Vorarlberg 0.023887 0.074557 0.320 0.749
L1.Wien -0.031846 0.138415 -0.230 0.818
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188131 0.028432 6.617 0.000
L1.Burgenland 0.090408 0.018877 4.789 0.000
L1.Kärnten -0.008823 0.010005 -0.882 0.378
L1.Niederösterreich 0.259918 0.039362 6.603 0.000
L1.Oberösterreich 0.138292 0.038448 3.597 0.000
L1.Salzburg 0.045620 0.020161 2.263 0.024
L1.Steiermark 0.021015 0.026321 0.798 0.425
L1.Tirol 0.093069 0.021349 4.359 0.000
L1.Vorarlberg 0.056304 0.018315 3.074 0.002
L1.Wien 0.117181 0.034001 3.446 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.106967 0.028904 3.701 0.000
L1.Burgenland 0.046013 0.019190 2.398 0.016
L1.Kärnten -0.013851 0.010171 -1.362 0.173
L1.Niederösterreich 0.189904 0.040014 4.746 0.000
L1.Oberösterreich 0.301718 0.039086 7.719 0.000
L1.Salzburg 0.109797 0.020495 5.357 0.000
L1.Steiermark 0.103587 0.026758 3.871 0.000
L1.Tirol 0.105496 0.021703 4.861 0.000
L1.Vorarlberg 0.069016 0.018619 3.707 0.000
L1.Wien -0.019517 0.034565 -0.565 0.572
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.126669 0.052631 2.407 0.016
L1.Burgenland -0.050246 0.034943 -1.438 0.150
L1.Kärnten -0.040664 0.018519 -2.196 0.028
L1.Niederösterreich 0.171919 0.072861 2.360 0.018
L1.Oberösterreich 0.138612 0.071170 1.948 0.051
L1.Salzburg 0.288890 0.037319 7.741 0.000
L1.Steiermark 0.035567 0.048723 0.730 0.465
L1.Tirol 0.163411 0.039518 4.135 0.000
L1.Vorarlberg 0.099765 0.033902 2.943 0.003
L1.Wien 0.068149 0.062939 1.083 0.279
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.056378 0.041831 1.348 0.178
L1.Burgenland 0.039537 0.027773 1.424 0.155
L1.Kärnten 0.051173 0.014719 3.477 0.001
L1.Niederösterreich 0.219056 0.057911 3.783 0.000
L1.Oberösterreich 0.294587 0.056567 5.208 0.000
L1.Salzburg 0.043778 0.029662 1.476 0.140
L1.Steiermark 0.000274 0.038725 0.007 0.994
L1.Tirol 0.143491 0.031409 4.568 0.000
L1.Vorarlberg 0.071921 0.026946 2.669 0.008
L1.Wien 0.080679 0.050025 1.613 0.107
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174074 0.049997 3.482 0.000
L1.Burgenland -0.002391 0.033194 -0.072 0.943
L1.Kärnten -0.062528 0.017592 -3.554 0.000
L1.Niederösterreich -0.077050 0.069215 -1.113 0.266
L1.Oberösterreich 0.189107 0.067608 2.797 0.005
L1.Salzburg 0.058166 0.035452 1.641 0.101
L1.Steiermark 0.234416 0.046284 5.065 0.000
L1.Tirol 0.498759 0.037541 13.286 0.000
L1.Vorarlberg 0.044687 0.032205 1.388 0.165
L1.Wien -0.054914 0.059789 -0.918 0.358
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160072 0.057793 2.770 0.006
L1.Burgenland -0.008333 0.038370 -0.217 0.828
L1.Kärnten 0.066397 0.020336 3.265 0.001
L1.Niederösterreich 0.206416 0.080008 2.580 0.010
L1.Oberösterreich -0.069127 0.078151 -0.885 0.376
L1.Salzburg 0.210975 0.040980 5.148 0.000
L1.Steiermark 0.120783 0.053502 2.258 0.024
L1.Tirol 0.072653 0.043394 1.674 0.094
L1.Vorarlberg 0.118924 0.037227 3.195 0.001
L1.Wien 0.122580 0.069113 1.774 0.076
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.358511 0.033137 10.819 0.000
L1.Burgenland 0.007257 0.022001 0.330 0.742
L1.Kärnten -0.023486 0.011660 -2.014 0.044
L1.Niederösterreich 0.214651 0.045874 4.679 0.000
L1.Oberösterreich 0.199225 0.044810 4.446 0.000
L1.Salzburg 0.044300 0.023497 1.885 0.059
L1.Steiermark -0.013689 0.030676 -0.446 0.655
L1.Tirol 0.104333 0.024881 4.193 0.000
L1.Vorarlberg 0.071334 0.021345 3.342 0.001
L1.Wien 0.039464 0.039627 0.996 0.319
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.039024 0.139606 0.192234 0.151017 0.117670 0.103150 0.064266 0.217058
Kärnten 0.039024 1.000000 -0.007719 0.131728 0.039412 0.093991 0.432824 -0.053982 0.097016
Niederösterreich 0.139606 -0.007719 1.000000 0.333929 0.141580 0.292901 0.096146 0.179947 0.312998
Oberösterreich 0.192234 0.131728 0.333929 1.000000 0.228285 0.325581 0.176204 0.167051 0.261085
Salzburg 0.151017 0.039412 0.141580 0.228285 1.000000 0.142629 0.112897 0.145364 0.123864
Steiermark 0.117670 0.093991 0.292901 0.325581 0.142629 1.000000 0.146654 0.137498 0.070877
Tirol 0.103150 0.432824 0.096146 0.176204 0.112897 0.146654 1.000000 0.112562 0.142511
Vorarlberg 0.064266 -0.053982 0.179947 0.167051 0.145364 0.137498 0.112562 1.000000 0.002121
Wien 0.217058 0.097016 0.312998 0.261085 0.123864 0.070877 0.142511 0.002121 1.000000